<?php

function arrMonth($month) {
    $arrmonth = array(
        "01" => "Januari",
        "02" => "Februari",
        "03" => "Maret",
        "04" => "April",
        "05" => "Mei",
        "06" => "Juni",
        "07" => "July",
        "08" => "Agustus",
        "09" => "September",
        "10" => "Oktober",
        "11" => "November",
        "12" => "Desember"
    );
    return $arrmonth[$month];
}

function pre($dt) {
    echo "<pre>";
    print_r($dt);
    echo "</pre>";
}

function l_query() {
    $ci = & get_instance();
    pre($ci->db->last_query());
}

function toObject($array) {
    $obj = new stdClass();
    foreach ($array as $key => $val) {
        $obj->$key = is_array($val) ? toObject($val) : $val;
    }
    return $obj;
}

function getAngkatan() {
    $ci = & get_instance();
    $ci->db->order_by("angkatan_year");
    return $ci->db->get("angkatan")->result();
}
function getPendingRegister() {
    $ci = & get_instance();
    $ci->db->select("count(*) jum")->where("status","pending");
    return $ci->db->get("regismanual")->row()->jum;
}

function getAngkatanName($id) {
    $ci = & get_instance();
    $ci->db->where("angkatan_year", $id);
    $dt = $ci->db->get("angkatan")->row();
    return @$dt->angkatan_name == "" ? "Angkatan " . ($id - 1994) : @$dt->angkatan_name;
}

function getEduType() {
    $ci = & get_instance();
    $ci->db->order_by("et_id");
    return $ci->db->get("education_type")->result();
}

function getPropinsi() {
    $ci = & get_instance();
    $ci->db->order_by("province_nama");
    return $ci->db->get("province")->result();
}

function getKabupaten($propinsiid) {
    $ci = & get_instance();
    $ci->db->where("province_id", $propinsiid);
    $ci->db->order_by("city_nama");
    return $ci->db->get("city")->result();
}

function getNamaPropinsi($propinsiid) {
    $ci = & get_instance();
    $ci->db->where("province_id", $propinsiid);
    return @$ci->db->get("province")->row()->province_nama;
}

function getNamaKota($cityid) {
    $ci = & get_instance();
    $ci->db->where("city_id", $cityid);
    return @$ci->db->get("city")->row()->city_nama;
}

function getCompanyName($companyid) {
    $ci = & get_instance();
    $ci->db->where("company_id", $companyid);
    return @$ci->db->get("company")->row()->company_name;
}

function validEmail($email) {
    $regex = @$strict ? '/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' : '/^([*+!.&#$¦\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i';
    return preg_match($regex, trim($email));
}

function arrStatus() {
    $arr = array(
        "s" => "Single",
        "m" => "Married"
    );
    return @$arr;
}

function getStatus($status) {
    $arr = arrStatus();
    return @$arr[$status];
}

function ifNull($str, $true = "", $false = "") {
    if ($str == "" && $true != "")
        return $true;
    if ($str != "" && $false != "")
        return $false;
    return $str;
}

function dateToString($strDate) {
    $date = explode("-", $strDate);
    return @$date[2] . " " . @arrMonth(@$date[1]) . " " . @$date[0];
}

function randomPassword() {
    $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 8; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}
?>
